package org.tity.commons.encrypt;

import java.io.IOException;

import org.tity.commons.encrypt.Rijndael.AESMode;

public class AESUtil {
	
	private static final String DEFAULT_KEY="tity_is_very_light_framework";
	private static final String DEFAULT_IV="show_me_the_money";
	
	public static Rijndael create()
	{
		return create(DEFAULT_KEY,DEFAULT_IV); //这两个字符串不允许改变
	}
	
	public static Rijndael create(String key,String iv)
	{
		byte[] keybsTmp = key.getBytes();
        byte[] ivbsTmp = iv.getBytes();
        
        
        byte[] keybs=new byte[16];
        if(keybsTmp.length<=keybs.length)
        {
        	System.arraycopy(keybsTmp, 0, keybs, 0, keybsTmp.length);
        }
        else
        {
        	System.arraycopy(keybsTmp, 0, keybs, 0, keybs.length);
        }

        byte[] ivbs=new byte[16];
        if(ivbsTmp.length<=ivbs.length)
        {
        	System.arraycopy(ivbsTmp, 0, ivbs, 0, ivbsTmp.length);
        }
        else
        {
        	System.arraycopy(ivbsTmp, 0, ivbs, 0, ivbs.length);
        }
        
        
        Rijndael cbc_aes_pkcs5 = new Rijndael(keybs, ivbs, AESMode.CBC_PKCS5);
        return cbc_aes_pkcs5;
	}
	
	public static void main(String[] args) throws IOException {
//		String a="你好，我是李方捷捷捷";
//		byte[] bb=FileUtil.readBytes(new File("C:\\Users\\Administrator\\Documents\\Tencent Files\\190868487\\FileRecv\\ext-addons-6.5.3-trial\\ext-addons-6.5.3\\packages\\d3\\d3.js"));
//		Rijndael r=AESUtil.create("a67890344", "aaa117890344");
//		byte[] bs=r.encrypt(bb);
//		String s1=new String(bs);
////		System.out.println(s1);
//		QuickLZ lz=new QuickLZ();
//		byte[] bs2=lz.compress(bs, 3);
////		String s2=new String(bs2);
//	
////		System.out.println(Hex.encodeHex(bs));
////		System.out.println(Hex.encodeHex(bs2));
//		FileUtil.writeBytes("C:\\1.data", bb);
//		FileUtil.writeBytes("C:\\2.data", bs);
//		FileUtil.writeBytes("C:\\3.data", bs2);
	}
 
	
}
